#!/bin/sh
set -e

clu_args=',add-master,add-slave,analyze,bakup-node,benchmark,check,count,create,del,dels,del-node,del-node-id,export,exporth,export-keys,export-keys-file,failover,fix-slot-cover,fix-slot-stable,flush,get,import,info,keys,keysize,monitor,querys,reshard,raminfo,set,safe-delete,others,-h,'


if [ ! -z $REDIS_HOST ] ; then
    sed -i 's/^REDIS_HOST.*/REDIS_HOST = '$REDIS_HOST'/g' /cluster/conf.properties
fi

if [ ! -z $REDIS_PORT ] ; then
    sed -i 's/^REDIS_PORT.*/REDIS_PORT = '$REDIS_PORT'/g' /cluster/conf.properties
fi

result=$(echo $clu_args|grep ",$1,"|xargs echo)

if [ "$result" != "" ]; then
	set -- java -jar /cluster/redis-cluster-manager-jar-with-dependencies.jar "$@"
fi

exec "$@"


# docker run -it -e REDIS_HOST=10.0.7.29 wolferhua/redis:clu-java args
